function qs(ele) {
    return document.querySelector(ele)
}
axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

//手机号码验证部分
let reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/

console.log('999')
//登录密码验证部分
let reg1 = /^[a-zA-Z]\w{5,17}$/

// console.log(qs('.td_right [checked]').value)
//点击注册按钮发起请求
qs('#btn_sub').addEventListener('click',async function (e) {
    e.preventDefault()
    if(!reg.test(qs('#phone').value)) {
        return alert('请输入正确手机号')
    }
    if (!reg1.test(qs('#password').value)) {
        return alert('请输入正确密码')
    }
    const sex = Number(qs('.xingbie [checked]').value)
    const vip = Number(qs('.vip [checked]').value)
    const res = await axios({
        method: 'POST',
        url: '/user/reg',
        data: {
            username: qs('#username').value,
            password: qs('#password').value,
            phone: qs('#phone').value,
            sex: sex,
            vip: vip,
            question: qs('#question').value,
            answer: qs('#answer').value,

        }
    })
    console.log(res)
})

//点击跳转登录界面
qs('#login').addEventListener('click', function () {
    location.href = '/01-loginBaseCode/login.html'
})